﻿package mortal.game.view.copy.worldBoss.WorldBossAllot
{
    import Message.Client.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class WorldBossAllotWindow extends BaseWindow
    {
        private var _allotIcon:WorldBossAllotIcon;
        private var _info:SGuildItemBetUpdateInfo;
        private var _data:Array;
        private var _nameBg:GImageBitmap;
        private var _nameImg:GImageBitmap;
        private var _cellList:Vector.<WorldBossAllotCell>;
        private var _attentionBmp:GImageBitmap;
        private var _attentionText:GTextFiled;
        private var _btnMinimize1:GLoadedButton;

        public function WorldBossAllotWindow(param1:ILayer = null)
        {
            this._cellList = new Vector.<WorldBossAllotCell>;
            super(param1);
            setSize(910, 450);
            title = Language.getString(21458);
            this._allotIcon = new WorldBossAllotIcon(this);
            this.configEventListener(WindowEvent.CLOSE, this.onClose);
            return;
        }// end function

        override protected function setWindowCenter() : void
        {
            _windowCenter = ResourceConst.getScaleBitmap(ImagesConst.PanelBg);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._btnMinimize1 = UIFactory.gLoadedButton(ImagesConst.MinimizeButton_upSkin, 880, 9 - _contentTopOf3DSprite.y + _contentY, 22, 20, contentTopOf3DSprite);
            this._btnMinimize1.configEventListener(MouseEvent.CLICK, this.onClickMinimize);
            this._nameBg = UIFactory.gImageBitmap(ImagesConst.ResultWinTypeBg, 214, 40, this);
            this._nameImg = UIFactory.gImageBitmap("", 250, 48, this, this.onNameImgLoaded);
            this._attentionBmp = UIFactory.gImageBitmap(ImagesConst.WorldBossAllotAttention, 84, 371, this);
            this._attentionText = UIFactory.gTextField("", 160, 365, 600, 60, this, GlobalStyle.textFormatLv);
            this._attentionText.multiline = true;
            this._attentionText.wordWrap = true;
            var _loc_1:* = Language.getString(21459);
            this._attentionText.htmlText = _loc_1;
            this.updateShowList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._nameBg.dispose(param1);
            this._nameBg = null;
            this._nameImg.dispose(param1);
            this._nameImg = null;
            this._attentionBmp.dispose(param1);
            this._attentionBmp = null;
            this._attentionText.dispose(param1);
            this._attentionText = null;
            this._btnMinimize1.dispose(param1);
            this._btnMinimize1 = null;
            var _loc_2:* = this._cellList.length - 1;
            while (_loc_2 >= 0)
            {
                
                this._cellList[_loc_2].dispose();
                _loc_2 = _loc_2 - 1;
            }
            this._cellList = new Vector.<WorldBossAllotCell>;
            super.disposeImpl(param1);
            return;
        }// end function

        override protected function closeBtnClickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WorldBossAllotHide, this._info.bossCode));
            super.closeBtnClickHandler(event);
            this._allotIcon.hide();
            return;
        }// end function

        protected function onClose(event:Event) : void
        {
            if (this._info && this._info.status != EWorldBossAllotStatus._EEnd)
            {
                this._allotIcon.show();
            }
            return;
        }// end function

        protected function onClickMinimize(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        public function updateData(param1:SGuildItemBetUpdateInfo, param2:Array) : void
        {
            this._info = param1;
            this._data = param2;
            this.updateShowList();
            return;
        }// end function

        public function updateShowList() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:String = null;
            var _loc_6:Boolean = false;
            var _loc_7:WorldBossAllotCell = null;
            if (this._info && this._data && !isDisposed)
            {
                _loc_1 = Math.min(this._cellList.length, this._data.length);
                _loc_2 = 0;
                while (_loc_2 < _loc_1)
                {
                    
                    this._cellList[_loc_2].data = this._data[_loc_2];
                    _loc_2++;
                }
                _loc_2 = this._cellList.length - 1;
                while (_loc_2 >= _loc_1)
                {
                    
                    this._cellList.pop().dispose();
                    _loc_2 = _loc_2 - 1;
                }
                _loc_2 = _loc_1;
                while (_loc_2 < this._data.length)
                {
                    
                    _loc_7 = UIFactory.getUICompoment(WorldBossAllotCell, 0, 0, this);
                    _loc_7.createDisposedChildren();
                    _loc_7.data = this._data[_loc_2];
                    this._cellList[_loc_2] = _loc_7;
                    _loc_2++;
                }
                _loc_2 = 0;
                while (_loc_2 < this._cellList.length)
                {
                    
                    this._cellList[_loc_2].x = 29 + 217 * _loc_2;
                    this._cellList[_loc_2].y = 84;
                    _loc_2++;
                }
                _loc_3 = 217 * (4 - this._data.length);
                this._btnMinimize1.x = 880 - _loc_3;
                _closeBtn.x = 910 - _loc_3;
                this._nameBg.x = 214 - _loc_3 / 2;
                setSize(910 - _loc_3, 430);
                title = Language.getString(21458);
                _loc_4 = this._info.bossCode;
                _loc_5 = WorldBossConfig.instance.getWorldBossByCode(_loc_4).bossNameImage;
                this._nameImg.imgUrl = _loc_5;
                _loc_6 = this._info.status == EWorldBossAllotStatus._EEnd;
                this._btnMinimize1.visible = !_loc_6;
                _closeBtn.visible = _loc_6;
            }
            return;
        }// end function

        private function onNameImgLoaded() : void
        {
            this._nameImg.x = (454 - this._nameImg.width) / 2 + this._nameBg.x;
            return;
        }// end function

    }
}
